package com.yimin.floatball.util

import android.content.res.Resources
import android.util.TypedValue

object CommonUtil {
    /**
     * 获取状态栏高度
     */
    fun getStatusBarHeight(): Int {
        return try {
            val resources = Resources.getSystem()
            val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
            resources.getDimensionPixelSize(resourceId)
        } catch (e: Exception) {
            0
        }
    }

    /**
     * dp to px
     */
    fun dip2px(dip: Float): Int {
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, dip, Resources.getSystem().displayMetrics
        ).toInt()
    }
}